package com.hui.xiao.xiaohui.ui;

import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.Toast;

import com.hui.xiao.xiaohui.R;

/**
 * Created by Administrator on 2016/5/21.
 */
public class NumberPickerTest extends Activity {
    NumberPicker np1, np2;
    int minPrice = 25, maxPrice = 75;
    EditText text ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.number_picker);
        text = (EditText) findViewById(R.id.show);
        np1 = (NumberPicker) findViewById(R.id.np1);
        np1.setMinValue(10);
        np1.setMaxValue(50);
        np1.setValue(minPrice);
        np1.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                minPrice = newVal;
                showSelectedPrice();
            }
        });
        np2 = (NumberPicker) findViewById(R.id.np2);
        np2.setMinValue(60);
        np2.setMaxValue(100);
        np2.setValue(maxPrice);
        np2.setOnValueChangedListener(new NumberPicker.OnValueChangeListener() {
            @Override
            public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
                maxPrice = newVal;
                showSelectedPrice();
            }
        });
    }

    void showSelectedPrice() {
        text.setText(String.format("你选中的最低价格是:%d , 最高价格是: %d", minPrice, maxPrice));
    }
}
